//
//  FANStackTools.m
//  Weibo - OC
//
//  Created by user on 16/4/26.
//  Copyright © 2016年 user. All rights reserved.
//

#import "FANStackTools.h"

@interface FANStackTools ()


@end

@implementation FANStackTools

- (void)setIsKeyBoard:(BOOL)isKeyBoard{
    
    _isKeyBoard = isKeyBoard;
    
    UIButton *button = [self viewWithTag:Emoticon];
    
    if (isKeyBoard) {
        
        
        [button setImage:[UIImage imageNamed:@"compose_emoticonbutton_background"] forState:UIControlStateNormal];
        
        [button setImage:[UIImage imageNamed:@"compose_emoticonbutton_background_highlighted"] forState:UIControlStateHighlighted];
    }else{
        
        [button setImage:[UIImage imageNamed:@"compose_keyboardbutton_background"] forState:UIControlStateNormal];
        
        [button setImage:[UIImage imageNamed:@"compose_keyboardbutton_background_highlighted"] forState:UIControlStateHighlighted];
    }
}

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        
        [self setupUI];
        
        self.distribution = UIStackViewDistributionFillEqually;
    }
    
    return self;
}

- (void)setupUI{
    
    [self addStackButton:@"compose_toolbar_picture" andType:Picture];
    [self addStackButton:@"compose_mentionbutton_background" andType:Mention];
    [self addStackButton:@"compose_trendbutton_background" andType:Trend];
    [self addStackButton:@"compose_emoticonbutton_background" andType:Emoticon];
    [self addStackButton:@"compose_add_background" andType:Add];

}

- (void)didStackButton:(UIButton *)button{
    
    __weak typeof(self) weakSelf = self;
    
    weakSelf.StackBlock((FANComposeToolsType)button.tag);
}

- (void)addStackButton:(NSString *)imageName andType:(FANComposeToolsType)type{
    
    UIButton *button = [[UIButton alloc] init];
    
    button.tag = type;
    
    [button addTarget:self action:@selector(didStackButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    
    [button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageName]] forState:UIControlStateHighlighted];
    
    [button setBackgroundImage:[UIImage imageNamed:@"compose_toolbar_background"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"compose_toolbar_background"] forState:UIControlStateHighlighted];
    
    [self addArrangedSubview:button];

}

@end
